<template>
	<view class="browsing-wrapper colRange wrapperLayer">
		<titleBar :titleText='"浏览足迹"' :pageForm='"browsing"' @cleanAll="clean"></titleBar>
		<view class="colRange browsingGoodslist borderBox">
			<view class="goodslist-wrapper borderBox rowCenter">
				<view class="goods-items borderBox colRange" v-for="(items,index) in footprints" :key='index'>
					<view class="items-container borderBox colRange">
						<view class="image-container defImg">
							<image :src="items.imgs" mode=""></image>
						</view>
						<view class="goodsInfo colCenBet borderBox">
							<view class="goodsName-box rowCenter">
								<image class="logoicon" src="../../../static/img/search/tm.png" mode=""></image>
								<view class="goodsText">
									{{items.itemTitle}}
								</view>
							</view>
							<view class="couponInfo-bar rowCenter">
								<view class="couponbox">
									{{items.couponMoney}}元券
								</view>
							</view>
							<view class="goodsPrice-goodSale rowRangeAve">
								<view class="goods-price rowEnd">
									<view class="after">券后<span class='rmb'>￥</span></view>
									<view class="price">{{items.itemendPrice}}</view>
								</view>
								<view class="saleNum-box">
									已售{{items.itemSale}}
								</view>
							</view>
						</view>
					</view>
				</view>
				<view class="empty-container colRanges" style="width: 100%;height: 100%;margin-top: 30vh;" v-if="loadStatus=='nomore' && footprints.length==0">
					<view class="defImg" style="width: 200rpx; height: 200rpx;" >
						<image src="../../../static/img/goods/empty.png" mode="aspectFill"></image>
					</view>
					<view class="texttips" style="margin-top: 40rpx; font-size: 28rpx;font-weight: 400;color: #666666;width: 100%; text-align: center;">
						您还没有浏览过商品哦~
					</view>
				</view>
				<view style="width: 100%;" v-else>
					<u-loadmore :status="loadStatus" :icon-type="iconType" :load-text="loadText" />
				</view>
			</view>
		</view>
		
		<u-modal v-model="showModel" :show-title="false" :show-cancel-button="true" :content="'确定要清空浏览记录嘛？'" @confirm="confirm" :async-close="true"></u-modal>
	</view>
</template>

<script>
	import titleBar from '../../../components/customize/titlebar.vue'
	export default {
		components: {
			titleBar
		},
		data() {
			return {
				footprints: [],
				loadStatus: 'loading',
				iconType: 'flower',
				loadText: {
					loadmore: '轻轻上拉',
					loading: '努力加载中',
					nomore: '实在没有了'
				},
				currentPage: 1,
				showModel: false,
				canloadMore: false
			}
		},
		onLoad() {
			this.getData();
		},
		methods: {
			getData() {
				debugger
				//获取足迹
				this.$u.api.user.footprints({
					pageNum: this.currentPage,
					pageSize: 10,
				}).then((res) => {
					debugger
					if (res.code == 200){
						if (res.rows.length < 10) {
							this.canloadMore = false
							this.loadStatus = 'nomore'
						} else {
							this.currentPage = ++ this.currentPage;
							this.loadStatus = 'loading'
							this.canloadMore = true
						}
						if (this.currentPage > 1) {
							this.footprints = this.footprints.concat(res.rows)
						} else {
							this.footprints = res.rows
						}
					}
				})
			},
			clean(){
				this.showModel = true
			},
			confirm(){
				this.$http.post('browsingHistory/cancelBrowsing').then(res=>{
					this.showModel = false
					this.goodsList = []
				})
			}
		},
		onReachBottom() {
			if (this.canloadMore) {
				this.getData()
			}
		},
		onPullDownRefresh() {
			this.currentPage = 0
			this.goodsList = []
			this.getData()
		}
	}
</script>

<style lang="scss">
	.browsing-wrapper {
		width: 100%;
	}

	.browsingGoodslist {
		width: 100%;
		margin-top: 20rpx;
		background-color: #F0F1F7;

		.goodslist-wrapper {
			width: 100%;
			padding: 0 22rpx;
			flex-wrap: wrap;

			.goods-items {
				width: 50%;
				height: 490rpx;
				margin-bottom: 20rpx;

				.items-container {
					width: 340rpx;
					height: 100%;
					margin: 10rpx 0;
					background-color: #FFFFFF;
					padding: 10rpx;

					.image-container {
						width: 100%;
						height: 310rpx;
					}

					.goodsInfo {
						width: 100%;
						height: 160rpx;
						margin-top: 10rpx;

						.goodsName-box {
							width: 100%;

							.logoicon {
								width: 50rpx;
								height: 24rpx;
								margin-right: 10rpx;
							}

							.goodsText {
								width: 250rpx;
								font-size: 28rpx;
								font-weight: 400;
								color: #333333;
								white-space: nowrap;
								overflow-x: hidden;
								text-overflow: ellipsis;
							}
						}

						.couponInfo-bar {
							width: 100%;

							.couponbox {
								width: 100rpx;
								height: 30rpx;
								line-height: 30rpx;
								text-align: center;
								background: url(../../../static/img/goods/couponbac.png)no-repeat;
								background-size: 100% 100%;
								font-size: 20rpx;
								font-weight: 500;
								color: #FF4242;
								margin-right: 10rpx;
							}

							.backPrice {
								width: 100rpx;
								height: 30rpx;
								background: linear-gradient(-90deg, #7619EC, #A429F3);
								border-radius: 5rpx;
								font-size: 20rpx;
								font-weight: 500;
								text-align: center;
								line-height: 30rpx;
								color: #FFFFFF;
							}
						}

						.goodsPrice-goodSale {
							width: 100%;
							margin-bottom: 10rpx;

							.goods-price {
								.after {
									font-size: 20rpx;
									font-weight: 400;
									color: #999999;
									line-height: 42rpx;

									.rmb {
										font-size: 22rpx;
										color: #FF4242;
									}
								}

								.price {
									color: #FF4242;
									font-weight: 500;
									font-size: 34rpx;
								}
							}

							.saleNum-box {
								font-size: 20rpx;
								font-weight: 400;
								color: #999999;
							}
						}
					}
				}
			}
		}
	}
</style>
